package book.dao.impl;

import java.util.ArrayList;
import java.util.List;

import book.dao.IBookDao;
import book.po.Book;
/**
 * 数据访问对象实现类——内存
 * 内存存储对象
 */
public class BookDaoMemoryImpl implements IBookDao {
	private static List<Book> library = new ArrayList<Book>(); //static确保所有service对象共用图书集合
	static {
		List<Book> bookList = new ArrayList<Book>();
		int bookIsbn[] = { 978701, 978702, 978703, 978704, 978705, 978706, 978707 };
		String bookName[] = { "Java基础教程", "XML基础教程", "JSP基础教程", "C++基础教程", "J2ME编程", "操作系统", "数据库技术" };
		double bookPrice[] = { 29.0, 21.0, 22.0, 29.0, 34.0, 32.0, 29.0 };
		for (int k = 0; k < bookIsbn.length; k++) {
			Book book = new Book();
			book.setIsbn(bookIsbn[k]);
			book.setName(bookName[k]);
			book.setPrice(bookPrice[k]);
			bookList.add(book);
		}
		library = bookList;
	}

	@Override
	public void save(Book book) {
		library.add(book);
		
	}

	@Override
	public void update(int id,Book book) {
		library.set(id, book);
	}

	@Override
	public Book get(int id) {
		return library.get(id);
	}

	@Override
	public void delete(int id) {
		library.remove(id);
	}

	@Override
	public List<Book> findAll() {
		return library;
	}

	@Override
	public void update(Book book) {
		// 数据库DAO专用更新接口
		
	}
}
